<template>
  <div class="user-info">
    <!-- 个人信息 -->
    <el-form label-width="220px">
      <!--手机 -->

      <el-form-item label="手机">
        <el-input v-model="userInfo.mobile" style="width:220px" />
      </el-form-item>

      <!-- 工号 入职时间 -->

      <el-form-item label="入职时间">
        <el-date-picker
          v-model="userInfo.timeOfEntry"
          type="date"
          class="inputW"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>

      <!-- 员工照片 -->

      <el-form-item label="员工头像">
        <Upload v-model="userInfo.staffPhoto"/>
      </el-form-item>

      <!-- 保存个人信息 -->
      <el-form-item>
        <el-button type="primary" @click="submit">保存更新</el-button>
        <el-button @click="$router.back()">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
  import { getuserhead } from '@/api/user'
  import { saveUserDetailById } from '@/api/employees'
  import Upload from '@/components/Upload/index.vue'


export default {
    data() {
        return {
            userId: this.$route.params.id,
            userInfo: {
                mobile: "",
                timeOfEntry: ""
            }
        };
    },
    created() {
        this.loaduserhead();
    },
    methods: {
        // 点击触发修改函数
        submit() {
            this.loadUserDetailById();
        },
        // 修改数据
        async loadUserDetailById() {
            try {
                const res = await saveUserDetailById(this.userInfo);
                this.$message.success(res.message);
                this.$router.back();
                // 保存数据 
            }
            catch (err) {
                console.log("saveUserDetailById", err);
            }
        },
        // 获取数据
        async loaduserhead() {
            try {
                const res = await getuserhead(this.userId);
                console.log("getuserhead", res);
                // 保存数据 
                this.userInfo = res.data;
            }
            catch (err) {
                console.log("getuserhead", err);
            }
        },
    },
    components: { Upload, Upload, Upload }
}
</script>

<style scoped lang="scss">
  .user-info{
    padding-top:20px;
  }
</style>